package lschgcdev.gdx.ui;
import lschgcdev.tdgame.ui.*;
import lschgcdev.gdx.*;
import lschgcdev.gdx.physic.GDXPickable;
import lschgcdev.tdgame.basic.*;

import com.badlogic.gdx.graphics.g2d.*;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.*;

public class GDXButton extends Button implements GDXObject, GDXPickable
{
	Sprite sprite;
	
	public GDXButton(String ID, String pathTexture,int x, int y, int w, int h, int xR, int yR, int wR, int hR){
		this(ID, new Vector2i(x,y), new Vector2i(w,h));
		setSprite(pathTexture, new Vector2i(xR, yR), new Vector2i(wR, hR));
	}
	
	public GDXButton(String ID, int x, int y, int w, int h){
		this(ID, new Vector2i(x,y), new Vector2i(w,h));
	}
	
	public GDXButton(String ID, Vector2i loc, Vector2i dim){
		super("GDXButton_"+ID, loc, dim);
		gdxNodesPickable.add(this);
	}

	public void setSprite(String pathTexture, Vector2i startRP, Vector2i endRP){
		Texture text = new Texture(Gdx.files.internal(pathTexture));
		if(text != null)
			sprite = new Sprite(text, startRP.x, startRP.y, endRP.x, endRP.y);
	}
	
	@Override
	public void render() {
		if(sprite != null){
			GDXGame.sB.begin();
			GDXGame.sB.draw(sprite, loc.x, loc.y, dim.x, dim.y);
			GDXGame.sB.end();
		}
	}

	@Override
	public void pickable(Object obj) {
		if(!enabled)
			return;
		if(obj instanceof Vector2i){
			Vector2i v2i = (Vector2i)obj;
			boolean collideX = v2i.x > loc.x && v2i.x < loc.x + dim.x,
					collideY = v2i.y > loc.y && v2i.y < loc.y + dim.y;
			if(collideX && collideY){
				
			}
		}
			
	}
	
}
